package com.lk2.core.util
{
		import flash.utils.describeType;
		
		import mx.logging.ILogger;
		import mx.logging.Log;
		import mx.logging.targets.TraceTarget;
		
		
		public class LogFactory{
			
			private static var initialized:Boolean = false;
		
			public function LogFactory() {
				init();
			}
				
			public static function init(filter:Array = null,logLevel:int=0):void {
				if (initialized) return;
				// reset logger
				Log.flush(); 
				Log.removeTarget(new TraceTarget());
				
				var logTrace:TraceTarget = new TraceTarget();
	
	            // set default value if filter is null 
	            if(filter==null){
	           		logTrace.filters=["*"];
	            } else  {
	            	logTrace.filters=filter
	            }
			
	            // set log level
	            logTrace.level = logLevel;
	           
	            // Add date, time, category, and log level to the output.
	            logTrace.includeDate = true;
	            logTrace.includeTime = true;
	            logTrace.includeCategory = true;
	            logTrace.includeLevel = true;
	

	          Log.addTarget(logTrace);
	          initialized = true;
	           
			}
			
			public static function getLogger(obj:Object):ILogger{
				init();
				// setup invalid chars
				var invalidChar:String = ":";
				
				// get package name by reflecton 
				var category:XML = describeType(obj);
				
				// replace ":" invalid chars
				var loggerName:String = category.@name
				while (loggerName.indexOf(invalidChar) > 0){
					loggerName = loggerName.replace(invalidChar,"_");
				}
				return Log.getLogger(loggerName); 
			}
		
		}
		

}
